﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
namespace DAO
{
    public class LOPDAO
    {
        QUANLY_DIEMDataContext DB = new QUANLY_DIEMDataContext();
        public int get_makh(int malop)
        {
            int makh = (from p in DB.LOPs where p.MALOP == malop select p.MAKH).Single();
            return makh;
        }
        public List<LOPDTO> layDSL()
        {
            try
            {
                List<LOPDTO> DS_lop = new List<LOPDTO>();
                var ds=from p in DB.LOPs select p;
                foreach (var child in ds)
                {
                    LOPDTO lop = new LOPDTO();
                    lop.MALOP = child.MALOP;
                    lop.TENLOP = child.TENLOP;
                    lop.MAKH = child.MAKH;
                    DS_lop.Add(lop);
                }
                return DS_lop;

            }
            catch {
                return null;
            }
        }
        //lấy tên lớp học sinh theo mã học sinh
        public string LayTenLop(int mahs)
        {
            try
            {
                NAMHOCDAO namdao = new NAMHOCDAO();
                int namhoc = namdao.LoadNamHocHienTai().MANAMHOC;
                string tenlop = (from p in DB.CHITIETHOCSINHs
                             join l in DB.LOPs
                             on p.MALOP equals l.MALOP
                             where p.MAHS == mahs && p.MANAMHOC == namhoc
                             select l.TENLOP).Single();
                return tenlop;
            }
            catch
            {
                return "";
            }
        }
       
    }
  
}
